/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.src;

/**
 *
 * @author Administrator
 */
public class NewJFrame extends javax.swing.JFrame {

    /**
     * Creates new form NewJFrame
     */
    public NewJFrame() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        screen = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        ac = new javax.swing.JButton();
        ac1 = new javax.swing.JButton();
        acv = new javax.swing.JButton();
        acc = new javax.swing.JButton();
        ac2 = new javax.swing.JButton();
        aci = new javax.swing.JButton();
        ac3 = new javax.swing.JButton();
        acd = new javax.swing.JButton();
        ac4 = new javax.swing.JButton();
        ac5 = new javax.swing.JButton();
        ac6 = new javax.swing.JButton();
        acf = new javax.swing.JButton();
        ac7 = new javax.swing.JButton();
        ac8 = new javax.swing.JButton();
        ac9 = new javax.swing.JButton();
        ac0 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("显示"));

        screen.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        screen.setText("0");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(screen)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(29, 29, 29)
                .addComponent(screen, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(30, Short.MAX_VALUE))
        );

        jPanel2.setLayout(new java.awt.GridLayout(4, 4));

        ac.setText("AC");
        ac.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                acActionPerformed(evt);
            }
        });
        jPanel2.add(ac);

        ac1.setText("+");
        ac1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ac1ActionPerformed(evt);
            }
        });
        jPanel2.add(ac1);

        acv.setText("-");
        jPanel2.add(acv);

        acc.setText("×");
        jPanel2.add(acc);

        ac2.setText("1");
        ac2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ac2ActionPerformed(evt);
            }
        });
        jPanel2.add(ac2);

        aci.setText("2");
        aci.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aciActionPerformed(evt);
            }
        });
        jPanel2.add(aci);

        ac3.setText("3");
        ac3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ac3ActionPerformed(evt);
            }
        });
        jPanel2.add(ac3);

        acd.setText("/");
        jPanel2.add(acd);

        ac4.setText("4");
        jPanel2.add(ac4);

        ac5.setText("5");
        jPanel2.add(ac5);

        ac6.setText("6");
        jPanel2.add(ac6);

        acf.setText(".");
        jPanel2.add(acf);

        ac7.setText("7");
        jPanel2.add(ac7);

        ac8.setText("8");
        jPanel2.add(ac8);

        ac9.setText("9");
        jPanel2.add(ac9);

        ac0.setText("0");
        jPanel2.add(ac0);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
NewClass scalc = new NewClass();
    
    private boolean newInput = true;

    private void acActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_acActionPerformed
        // TODO add your handling code here:
       this.screen.setText("0");
        scalc.ac(); 
    }//GEN-LAST:event_acActionPerformed

    private void ac1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ac1ActionPerformed
        // TODO add your handling code here:
        String screenThing =  screen.getText();
         try{
            double screenNumber = Double.parseDouble(screenThing);
            scalc.add(screenNumber);
            screen.setText(scalc.getValue()+"");
            newInput = true;
        }catch(Exception e){
            e.printStackTrace();
        
    }                                   
    
    }//GEN-LAST:event_ac1ActionPerformed

    private void ac2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ac2ActionPerformed
        // TODO add your handling code here:
          if(newInput){
            screen.setText(0+"");
        }
        
        if(screen.getText().trim().equals("0")){
            screen.setText("1");
        }else{
            screen.setText(screen.getText()+"1");
        }
        newInput = false;

    }//GEN-LAST:event_ac2ActionPerformed

    private void aciActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aciActionPerformed
        // TODO add your handling code here:
          if(newInput){
            screen.setText(0+"");
        }
        
        if(screen.getText().trim().equals("0")){
            screen.setText("2");
        }else{
            screen.setText(screen.getText()+"2");
        }
        newInput = false;
    }//GEN-LAST:event_aciActionPerformed

    private void ac3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ac3ActionPerformed
        // TODO add your handling code here:
          if(newInput){
            screen.setText(0+"");
        }
        
        if(screen.getText().trim().equals("0")){
            screen.setText("3");
        }else{
            screen.setText(screen.getText()+"3");
        }
        newInput = false;
    }//GEN-LAST:event_ac3ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new NewJFrame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton ac;
    private javax.swing.JButton ac0;
    private javax.swing.JButton ac1;
    private javax.swing.JButton ac2;
    private javax.swing.JButton ac3;
    private javax.swing.JButton ac4;
    private javax.swing.JButton ac5;
    private javax.swing.JButton ac6;
    private javax.swing.JButton ac7;
    private javax.swing.JButton ac8;
    private javax.swing.JButton ac9;
    private javax.swing.JButton acc;
    private javax.swing.JButton acd;
    private javax.swing.JButton acf;
    private javax.swing.JButton aci;
    private javax.swing.JButton acv;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTextField screen;
    // End of variables declaration//GEN-END:variables
}
